/** 
访问数累计
@param { string }  collection    集合名称
@param { string }  id            当前对象ID
*/
const hitsCount = async (collection, id) => {
    return await wx.cloud.callFunction({
        name: 'countClick',
        data: {
            collection,
            id
        }
    })
}

/**
 * 添加收藏
 * @param  {string}   thisCategory   收藏对象类别（article,food）
 * @param  {string}   openid         收藏者OPENID
 * @param  {object}   detail         收藏对象详情信息
 * @param  {string}   thisID         收藏对象ID
 */
const addCollect = async (thisCategory, openid, detail, thisID) => {
    return await wx.cloud.callFunction({
        name: 'addCollect',
        data: {
            thisCategory,
            openid,
            detail,
            thisID
        }
    })
}

/**
 * 取消收藏
 * @param  {string}   thisCategory   收藏对象类别（article,food）
 * @param  {string}   openid         收藏者OPENID
 * @param  {string}   thisID         收藏对象ID
 */

const removeCollect = async (thisCategory, openid, thisID) => {
    return await wx.cloud.callFunction({
        name: 'removeCollect',
        data: {
            thisCategory,
            thisID,
            openid
        }
    })
}

module.exports = {
    hitsCount,
    addCollect,
    removeCollect
}